﻿using EnvDTE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace Axiom.CodeManifold
{
	public class Parameter
	{
		public Parameter()
		{
			Comment = string.Empty;
			Modifier = string.Empty;
			Name = string.Empty;
			Type = string.Empty;
		}

		public Parameter(CodeParameter parameter)
		{
			this.Name = parameter.Name;
			this.Comment = parameter.DocComment;
			this.Modifier = parameter.Type.CodeType.Name;
			this.XCodeElement = new XCodeElement(parameter);

			if (string.IsNullOrWhiteSpace(this.Comment))
			{
				Comment = this.Name.SplitPascalCase();
			}
		}

		public string Comment { get; set; }
		public string Modifier { get; set; }
		public string Name { get; set; }
		public string Type { get; set; }

		[XmlIgnore]
		public string DocComment
		{
			get
			{
				var sb = new StringBuilder();

				sb.AppendFormat("<param name=\"{0}\">", Name);
				sb.Append(Comment);
				sb.AppendLine("</param>");

				return sb.ToString();
			}
		}

		[XmlIgnore]
		public XCodeElement XCodeElement { get; set; }
	}
}
